﻿(function($){
    $.fn.JNMagnifier=function(setting){
    	this.each(function(){
			if(setting&&setting.renderTo){
				if(typeof(setting.renderTo)=="string"){
					setting.renderTo = $(setting.renderTo);
				}
			}else{
				return;
			}
			var _img_org_ = $(this).children("img");
			_img_org_.css("cursor","pointer");

			var __w = _img_org_.width();
			var __h = _img_org_.height();

			var _val_w = (setting.renderTo.width() / 2);
			var _val_h = (setting.renderTo.height() / 2);
			var _val_index;
			$(this).mouseover(function(){
				_val_index = $(this).index();
				var __left;
				if(_val_index==0 || _val_index==4){
					__left = 185;
				}
				else if(_val_index==1 || _val_index==5){
					__left = 360
				}
				else if(_val_index==2 || _val_index==6){
					__left = -24
				}
				else if(_val_index==3 || _val_index==7){
					__left = 150
				}
				var __top = _img_org_.position().top;
				setting.renderTo.html('<table><tr><td><img src="' + _img_org_.attr("src") + '" id="JNMagnifierrenderToImg" /></td></tr></table>');
				setting.renderTo.css({
				  "left":__left,
				  "top":"50px"
				  });
				timer = setInterval(function(){
					setting.renderTo.show();
				},1000);
			});
			
			$(this).mouseout(function(){
					setting.renderTo.hide();
					setting.renderTo.html();
					clearInterval(timer);
			});
			$(".ShowBigPictureBox").mouseleave(function(){
					setting.renderTo.hide();
					setting.renderTo.html();
					clearInterval(timer);
			});
    	})
    		}
})(jQuery);